/*
 * @lc app=leetcode.cn id=53 lang=csharp
 *
 * [53] 最大子数组和
 */

// @lc code=start
public class Solution {
    public int MaxSubArray(int[] nums) {
        int max = nums[0];
        int sum = 0;
        foreach (var num in nums)
        {
            if (sum > 0)
            {
                sum += num;
            }
            else
            {
                sum = num;
            }
            max = Math.Max(max, sum);
        }
        return max;
    }
}
// @lc code=end

